from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from rest_framework import status
from rest_framework.decorators import api_view
from .serializers import MqttServerSenserSerializer
# Create your views here.

from django.http import HttpResponse, JsonResponse
from rest_framework.parsers import JSONParser

from  .models import MqttTopic,MqttServer

@csrf_exempt
def mqttConfig(request):
    if request.method == 'GET':
        mqttServer = MqttServer.objects.get(ip_address=request.GET.get('ip'))
        mqttServerSerializer = MqttServerSenserSerializer(mqttServer)
        print(mqttServerSerializer)
        return JsonResponse(mqttServerSerializer.data, status=status.HTTP_200_OK,safe=False)

